package net.zjitc.servlet;

import net.zjitc.domain.User;
import net.zjitc.service.UserService;
import net.zjitc.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created by Administrator on 2017/9/29.
 */
@WebServlet(name = "LoginServlet",urlPatterns = "/loginServlet")
public class LoginServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String username = request.getParameter("user");
        String password = request.getParameter("pass");
        UserService userService = new UserServiceImpl();
        User user = null;
        user = userService.findByUsernameAndPassword(username,password);
        if (user != null){
            response.sendRedirect("/Web/success.jsp");
        }else {
            response.sendRedirect("/Web/login.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
